import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AliyunChatService } from './chat.service';
import { ChatGateway } from './chat.gateway';
import { ChatController } from './chat.controller';

@Global()
@Module({
  imports: [ConfigModule],
  controllers: [ChatController],
  providers: [
    AliyunChatService,
    ChatGateway,
    {
      provide: 'BIGMODEL_API_KEY',
      useFactory: (configService: ConfigService) => {
        const apiKey = configService.get<string>('bigModel.apiKey');
        if (!apiKey) {
          throw new Error('BIGMODEL_API_KEY 环境变量未配置');
        }
        return apiKey;
      },
      inject: [ConfigService],
    },
  ],
  exports: [AliyunChatService],
})
export class ChatModule {}
